/*
@ClassName DataScheduleController
@Description TODO
@Author SubUp
@Date   2022/8/4
@Version 1.0
*/

package com.sunjob.mrojobschedule.controller;

import com.sunjob.common.domain.scheduleServer.JobSchedule;
import com.sunjob.common.domain.scheduleServer.PlanSchedule;
import com.sunjob.common.mroAnno.ControllerLog;
import com.sunjob.common.mroAnno.LogModuleType;
import com.sunjob.common.result.Result;
import com.sunjob.mrojobschedule.service.AssertInvokeService;
import com.sunjob.mrojobschedule.service.ProductScheduleService;
import com.sunjob.mrojobschedule.service.ResumeInvokeService;
import com.sunjob.mrojobschedule.service.TechInvokeService;
import com.sunjob.mrojobschedule.util.ScheduleUtils;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

@RestController
@Api(tags = "零部件、交通工具信息展示",value = "提供零部件、交通工具信息展示页面上的各数据")
@RequestMapping("/manager/")
public class ProductScheduleController {
    @Resource
    private ProductScheduleService productScheduleService;
    @Autowired
    private TechInvokeService techInvokeService;
    @Autowired
    private AssertInvokeService assertInvokeService;
    @Autowired
    private ResumeInvokeService resumeInvokeService;

    @GetMapping("{examineId}/{kindId}")
    @ApiOperation(value = "分级分层展示零部件、车的简单信息")
    @ControllerLog(LogModuleType.PLAN)
    public Result<Map> generateProductMenu(@ApiParam(value = "检修对象选择",required = true) @PathVariable String examineId,
                                           @ApiParam(value = "二级分类ID",defaultValue = "1") @PathVariable String kindId){
        /*1--对应车辆*/
        if(ScheduleUtils.checkNumber(examineId) && ScheduleUtils.transferToInt(examineId)==1){

        }else{  //其他参数都默认为0,即零件

        }
//        Result allShapa2Composition = techInvokeService.getAllShapa2Composition();
        Result allShape = techInvokeService.getAllShape();
        Result allShapa2Composition = techInvokeService.getAllShapa2Composition();
        Result shape2CompositionById = techInvokeService.getShape2CompositionById(318387151249477L);
        ConcurrentHashMap map = new ConcurrentHashMap();
        map.put("shapa",allShape);
        map.put("shapa2",allShapa2Composition);
        map.put("shape2CompositionById",shape2CompositionById);
        return Result.ok(map,"upload product menu success");
    }
    /**
     * 搜索具体物品
     * @param examineId  检修对象枚举，0-零部件、1-交通工具
     * @param kindId     检修对象的二级名称id
     * @param productId  物品id
     * @return
     */
    @GetMapping("product/{examineId}/{kindId}/{productId}")
    @ApiOperation(value = "查询具体零部件、交通工具实例")
    @ControllerLog(LogModuleType.PLAN)
//    @ApiImplicitParams({
//            @ApiImplicitParam(value = "检修对象id",dataType = "int",paramType = "query",required = true),
//            @ApiImplicitParam(value = "检修对象二级id",dataType = "int",paramType = "query")
//    })
    public Result<Map> queryAllProducts(@ApiParam(value = "检修对象id",required = true,defaultValue = "0") @PathVariable String examineId,
                                        @ApiParam(value = "检修对象二级id",defaultValue = "1") @PathVariable String kindId,
                                        @ApiParam(value = "物品id",required = true) @PathVariable String productId){
        /*1--对应车辆*/
        if(ScheduleUtils.checkNumber(examineId) && ScheduleUtils.transferToInt(examineId)==1){

        }else{  //其他参数都默认为0,即零件

        }
        return Result.build(null,200,"load manager failure");
    }

    /**
     * 展示产品的详细信息
     * @param kindId
     * @param productId
     * @return
     */
    @GetMapping("product/info/{kindId}/{productId}")
    @ApiOperation(value = "展示产品的详细信息")
    @ControllerLog(LogModuleType.PLAN)
    public Result<Map> queryProduct(@ApiParam(value = "检修对象二级id",required = true) @PathVariable String kindId,
                                    @ApiParam(value = "产品id",required = true) @PathVariable String productId){
//        resumeInvokeService.selectCKparts();
        Result result = assertInvokeService.selectInstanceById(320389664038981L);
        return result;
//        return Result.build(null,200,"load detail message failure");
    }

    /**
     * 生成计划、窗口弹出需要的参数配置
     * @return
     */
    @GetMapping("param/plan")
    @ApiOperation(value = "生成计划、窗口弹出需要的参数配置")
    @ControllerLog(LogModuleType.PLAN)
    public Result<Map> unfoldParamPlan(){
        Map map = productScheduleService.generatePlanList();
        if(map.size()==0)
            return Result.build(null,200,"load unfold plan param failure");
        return Result.ok(map,"load unfold plan param success");

    }

    /**
     * 作业派发、窗口弹出需要的参数配置
     * @return
     */
    @GetMapping("param/job")
    @ApiOperation(value = "作业派发、窗口弹出需要的参数配置")
    @ControllerLog(LogModuleType.PLAN)
    public Result<Map> unfoldParamJob(){
        Map map = productScheduleService.generateJobList();
        if(map.size() != 0)
            return Result.ok(map,"load unfold plan param failure");
        return Result.build(null,200,"load unfold plan param success");
    }

    /**
     * 作业展示调度管理
     * @param scheduleId
     * @return
     */
    @GetMapping("menu/job/schedule/{scheduleId}")
    @ApiOperation(value = "作业展示调度管理")
    @ControllerLog(LogModuleType.PLAN)
    public Result<Map> unfoldParamScheduleJob(@ApiParam(value = "界面id",required = true) @PathVariable String scheduleId){
        Map map = productScheduleService.scheduleJobMenu(scheduleId);
        if(map.size() != 0)
            return Result.ok(map,"load job schedule data and param success");
        return Result.build(null,200,"load job schedule data and param failure");
    }

    /**
     * 计划展示调度管理
     * @param scheduleId
     * @return
     */
    @GetMapping("menu/plan/schedule/{scheduleId}")
    @ApiOperation(value = "计划展示调度管理")
    @ControllerLog(LogModuleType.PLAN)
    public Result<Map> unfoldParamSchedulePlan(@ApiParam(value = "界面id",required = true) @PathVariable String scheduleId){
        Map map = productScheduleService.schedulePlanMenu(scheduleId);
        if(map.size() != 0)
            return Result.ok(map,"load plan schedule data and  param success");
        return Result.build(null,200,"load plan schedule data and param failure");
    }

    /**
     * 故障处理，无需审批
//     * @param plan
//     * @param job
     * @return
     */
    @PostMapping("trouble/{job}")
    public Result<Integer> faultHandler(@ApiParam(value = "作业信息",required = true) @RequestBody JobSchedule job){
        Integer rt = productScheduleService.faultHandler(job);
        if(rt != 0){
            return Result.ok(rt,"trouble handlered with payout");
        }
        return Result.build(null,200,"trouble handler failure");
    }

    @GetMapping("census/{plan}")
    public Result<Integer> censusTransformation(){
        productScheduleService.censusTransformation("");
        return Result.ok(null,"ok");
    }


}
